package com.jdk.learn.collection;

/**
 * Created by baiguantao on 2017/12/25.
 *
 *
 *
 * 没有test方法的情况

 Compiled from "StringDemo.java"
 public class com.jdk.learn.collection.StringDemo {
 public com.jdk.learn.collection.StringDemo();
 Code:
 0: aload_0
 1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 4: return

 public static void main(java.lang.String[]);
 Code:
 0: ldc           #2                  // String abc    常量abc入栈
 2: astore_1                                            //把栈顶的值存到str变量里
 3: new           #3                  // class java/lang/StringBuilder   创建StringBuilder对象
 6: dup
 7: invokespecial #4                  // Method java/lang/StringBuilder."<init>":()V  //实例对象
 10: aload_1
 11: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
 14: ldc           #6                  // String def
 16: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
 19: invokevirtual #7                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
 22: astore_1
 23: new           #3                  // class java/lang/StringBuilder
 26: dup
 27: invokespecial #4                  // Method java/lang/StringBuilder."<init>":()V
 30: aload_1
 31: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
 34: ldc           #8                  // String ghi
 36: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
 39: invokevirtual #7                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
 42: astore_1
 43: return
 }



 */
public class StringDemo {
    public static void main(String[] args) {
        String s="abc";
        s+="def";
        s+="ghi";
        //上述方式会转成StringBuilder
    }


    /**
     *
     * 下面代码是在main注释的情况下生成的

     public static void test();
     Code:
     0: new           #2                  // class java/lang/StringBuilder
     3: dup
     4: invokespecial #3                  // Method java/lang/StringBuilder."<init>":()V
     7: astore_0
     8: aload_0
     9: ldc           #4                  // String abc
     11: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     14: pop
     15: aload_0
     16: ldc           #6                  // String def
     18: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     21: pop
     22: aload_0
     23: ldc           #7                  // String ghi
     25: invokevirtual #5                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     28: pop
     29: aload_0
     30: invokevirtual #8                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     33: pop
     34: return


     *
     */
    public static void  test(){
        StringBuilder sb=new StringBuilder();
        sb.append("abc");
        sb.append("def");
        sb.append("ghi");
        sb.toString();
    }
}
